package controller

import (
	"context"
	"net/http"
	"web/global"
	"web/model"
	"web/utils"

	"github.com/gin-gonic/gin"
)

func GetSmscd(ctx *gin.Context) {
	//获取数据
	mobile := ctx.Param("mobile")
	//获取输入的图片验证码
	text := ctx.Query("text")
	//获取验证码图片的uuid
	uuid := ctx.Query("id")

	res := model.CheckImgCode(uuid, text)
	resp := make(map[string]string)
	//校验数据
	if mobile == "" || text == "" || uuid == "" || !res {
		global.GlobalLog.Error(context.Background(), "传入数据错误")
		resp["errno"] = utils.RECODE_DATAERR
		resp["errmsg"] = utils.RecodeText(utils.RECODE_DATAERR)
	} else {

		resp["errno"] = utils.RECODE_OK
		resp["errmsg"] = utils.RecodeText(utils.RECODE_OK)
	}
	model.SaveSmsCode(mobile, text)
	//处理数据  放在服务端处理

	ctx.JSON(http.StatusOK, resp)
}
